package com.example.newsapp.ui.components.newsComponent

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.PagerState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.example.newsapp.data.compositionLocal.LocalNavController
import com.example.newsapp.data.`object`.PageNavigation

/**
 * 新闻页面上方搜索框
 *
 * @param interactionSource 交互状态
 */
@Composable
fun TopSearchFrame(
    interactionSource: MutableInteractionSource,
    modifier: Modifier = Modifier
) {
    val navController = LocalNavController.current
    Box {
        Row {
            OutlinedTextField(
                value = "",
                onValueChange = {},
                enabled = false,
                modifier = Modifier
                    .weight(1f)
                    .height(50.dp)
                    .clickable(
                        interactionSource = interactionSource,
                        indication = null
                    ) {
                        navController.navigate(PageNavigation.searchFrame)
                    }
                    .padding(start = 50.dp, top = 8.dp, end = 30.dp, bottom = 10.dp),
                shape = RoundedCornerShape(20.dp),
                leadingIcon = {
                    Icon(Icons.Default.Search, null)
                },
                colors = TextFieldDefaults.colors().copy(unfocusedContainerColor = Color(0x5CD7C9C9)),
                placeholder = {
                    Text("搜索感兴趣的新闻")
                }
            )
        }
        Text(
            text = "搜索感兴趣的新闻",
            modifier = Modifier.padding(start = 90.dp, top = 11.dp),
            color = Color(0xFF626262)
        )
    }
}